package com.truonghau.xmeasure.commons;

import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Message;
import android.widget.EditText;

import com.truonghau.model.ListMocDTO;
import com.truonghau.shipper.R;

public class CommonUtils {
	
	public static void getPopupTitleAndFileName(final Context context, String title, String sms, final ListMocDTO object, final int type,final Handler hl ) {
		AlertDialog.Builder alert = new AlertDialog.Builder(context);
		alert.setTitle(title);
		alert.setMessage(sms);
		final EditText input = new EditText(context); 
		input.setSelection(input.getText().length());
		alert.setView(input);
		alert.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
					if(input.getText() != null && !"".equals(input.getText().toString().trim())){
						if(type ==0)
							object.setTitle(input.getText().toString().trim());
						else	
						{
							object.setFileName(input.getText().toString().trim() + ".txt");
							Message msg = new Message();
							hl.sendMessage(msg);
						}
					}
					
			}
		});
		alert.show();
	}
	public static void getValuesFromPopup(final Context context, String title, String sms, final Handler hl) {
		AlertDialog.Builder alert = new AlertDialog.Builder(context);
		alert.setTitle(title);
		alert.setMessage(sms);
		final EditText input = new EditText(context); 
		input.setSelection(input.getText().length());
		alert.setView(input);
		alert.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
					if(input.getText() != null && !"".equals(input.getText().toString().trim())){
						Message msg = new Message();
						msg.obj = input.getText().toString().trim();
						hl.sendMessage(msg);
					}
					
			}
		});
		alert.show();
	}
	public static void getEditNamePointInList(final Context context, String title, String sms, final int index, final int total, final Handler hl, String oldText) {
		AlertDialog.Builder alert = new AlertDialog.Builder(context);
		alert.setTitle(title);
		alert.setMessage(sms);
		final EditText input = new EditText(context); 
		input.setText(oldText);
		input.setSelection(input.getText().length());
		alert.setView(input);
		alert.setPositiveButton(context.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
					if(input.getText() != null && !"".equals(input.getText().toString().trim())){
						Message msg = new Message();
						msg.obj = input.getText().toString().trim();
						//
						msg.arg1 = index;
						msg.arg2 = total;
						//
						hl.sendMessage(msg);
					}
					
			}
		});
		alert.show();
	}

	public static void callRemoveListMoc(final ListMocDTO ktt,
			Context context, final Handler deleteHandler,
			final List<ListMocDTO> items) {
		AlertDialog.Builder alert = new AlertDialog.Builder(context);
		alert.setTitle(context.getString(R.string.app_name));
		alert.setMessage(context.getString(R.string.deletePointConfirm));
		alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
				Message msg = new Message();
				int position = items.indexOf(ktt);
				msg.arg1 = position;
				deleteHandler.sendMessage(msg);
			}
		});
		alert.setNegativeButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						// nothing to do
					}
				});
		alert.show();
	}
	
	public static String getDirectionGeoGPS(Context context, float goc){
		int gocInt = (int) (goc+22.5)/45; 
		switch (gocInt) {
		case 1:
			return context.getString(R.string.directionEastNorth);
		case 2:
			return context.getString(R.string.directionEast);
		case 3:
			return context.getString(R.string.directionEastSouth);
		case 4:
			return context.getString(R.string.directionSouth);
		case 5:
			return context.getString(R.string.directionWestSouth);
		case 6:
			return context.getString(R.string.directionWest);
		case 7:
			return context.getString(R.string.directionWestNorth);
		default:
			return context.getString(R.string.directionNorth);
		}
	}

	
}
